package com.example.safeassistan.hiddendanger.adapter;

import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.safeassistan.R;
import com.example.safeassistan.hiddendanger.model.HiddenDangerMyModel;

import java.util.List;

public class HiddenDangerMyAdapter extends BaseQuickAdapter<HiddenDangerMyModel.ResultDTO,BaseViewHolder> {
    private String handletype="1";
    public HiddenDangerMyAdapter(@Nullable List<HiddenDangerMyModel.ResultDTO> data,String type) {
        super(R.layout.item_hiddendanger_my_list, data);
        this.handletype=type;
    }

    @Override
    protected void convert(BaseViewHolder helper, HiddenDangerMyModel.ResultDTO item) {
        ImageView ivImg=helper.getView(R.id.ivImg);
        TextView tvDot=helper.getView(R.id.tvDot);
        TextView tvStatus1=helper.getView(R.id.tvStatus1);

        if (item.getHdangerImg()!=null){
            String [] strs=item.getHdangerImg().split(",");
            Glide.with(mContext).load(strs[0].equals("")?strs[1]:strs[0])
                    .apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
                    .placeholder(R.mipmap.default_image).into(ivImg);
        }

        helper.setText(R.id.tvHiddendDangerName,item.getHdangerTitle()+"");
        helper.setText(R.id.tvOwer,item.getCreateBy()+"");
        helper.setText(R.id.tvDepartMent,item.getDepartName()+"");
        helper.setText(R.id.tvHiddendDangerType,item.getHiddenTypeName()+"");
        helper.setText(R.id.tvReform,item.getOverdue()==null?item.getAllottedTime():item.getOverdue());
        switch (item.getHdangerLevel()+""){
            case "3":
                helper.setText(R.id.tvHiddendDangerLevel,"一般");
                tvDot.setBackgroundResource(R.drawable.orange_circle);
                break;
            case "1":
                helper.setText(R.id.tvHiddendDangerLevel,"重大");
                tvDot.setBackgroundResource(R.drawable.red_circle);
                break;
        }

        if (handletype.equals("1")){
            switch (item.getDisposeStatus()+""){
                case "2":
                    //待评审
                    tvStatus1.setText("已提交");
                    helper.setText(R.id.tvHiddendDangerStatus,"已提交");
                    tvStatus1.setBackgroundResource(R.drawable.leftcorner_gray_bg);
                    break;
                case "3":
                    //待整改
                    tvStatus1.setText("已评审");
                    helper.setText(R.id.tvHiddendDangerStatus,"已评审");
                    tvStatus1.setBackgroundResource(R.drawable.leftcorner_gray_bg);
                    break;
                case "4":
                    // 待验收
                    tvStatus1.setText("已整改");
                    helper.setText(R.id.tvHiddendDangerStatus,"已整改");
                    tvStatus1.setBackgroundResource(R.drawable.leftcorner_gray_bg);
                    break;
                case "5":
                    //已验收
                    tvStatus1.setText("已验收");
                    helper.setText(R.id.tvHiddendDangerStatus,"已验收");
                    tvStatus1.setBackgroundResource(R.drawable.leftcorner_gray_bg);
                    break;
                case "6":
                    tvStatus1.setText("已撤销");
                    helper.setText(R.id.tvHiddendDangerStatus,"已撤销");
                    tvStatus1.setBackgroundResource(R.drawable.leftcorner_gray_bg);
                    break;
            }
        }else {
            switch (item.getDisposeStatus()+""){
                case "1":
                    //待提交
                    tvStatus1.setText("待提交");
                    helper.setText(R.id.tvHiddendDangerStatus,"待提交");
                    tvStatus1.setBackgroundResource(R.drawable.leftcorner_purple_bg);
                    break;
                case "2":
                    //待评审
                    tvStatus1.setText("待评审");
                    helper.setText(R.id.tvHiddendDangerStatus,"待评审");
                    tvStatus1.setBackgroundResource(R.drawable.leftcorner_green_bg);
                    break;
                case "3":
                    //待整改
                    if (item.getRectSubmit()==0){
                        tvStatus1.setText("待整改");
                        helper.setText(R.id.tvHiddendDangerStatus,"待整改");
                        tvStatus1.setBackgroundResource(R.drawable.leftcorner_blue_bg);
                     }else {
                        tvStatus1.setText("重新整改");
                        helper.setText(R.id.tvHiddendDangerStatus,"重新整改");
                        tvStatus1.setBackgroundResource(R.drawable.leftcorner_blue_bg);
                    }
                    break;
                case "4":
                    // 待验收
                        tvStatus1.setText("待验收");
                        helper.setText(R.id.tvHiddendDangerStatus,"待验收");
                        tvStatus1.setBackgroundResource(R.drawable.leftcorner_red_bg);
                    break;
                case "5":
                    //已验收
                    tvStatus1.setText("已完成");
                    helper.setText(R.id.tvHiddendDangerStatus,"已完成");
                    tvStatus1.setBackgroundResource(R.drawable.leftcorner_gray_bg);
                    break;
            }
        }
    }
}